<template>
  <div class="panel">
    <div class="title">后台管理系统</div>
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <el-tab-pane name="account">
          <template #label>
            <span class="custom-tabs-label">
              <el-icon><UserFilled /></el-icon>
              <span class="text">账号登录</span>
            </span>
          </template>
          <Account ref="accountRef" />
        </el-tab-pane>
        <el-tab-pane name="phone">
          <template #label>
            <span class="custom-tabs-label">
              <el-icon><Iphone /></el-icon>
              <span class="text">手机登录</span>
            </span>
          </template>
          <Phone />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="controns">
      <el-checkbox v-model="hasRemPwd" label="记住密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" @click="handleLoginBtnClick">立即登录</el-button>
  </div>
</template>

<script setup lang="ts">
import Account from './account.vue'
import Phone from './phone.vue'
import { ref, watch } from 'vue'
import { localCache } from '@/utils/cache'
import { HASREMPWD } from '@/types/constant'

const hasRemPwd = ref<boolean>(localCache.getCache(HASREMPWD) ?? false)
// 监听多选框的数值
watch(hasRemPwd, (newValue) => {
  localCache.setCache(HASREMPWD, newValue)
})
const activeName = ref('account')
// 判断用户点击的activeName
function handleLoginBtnClick() {
  if (activeName.value === 'account') {
    console.log('用户进行账户登录')
    accountRef.value?.loginAction(hasRemPwd.value)
  } else {
    console.log('用户进行手机登录')
  }
}
// ref调用子组件方法
const accountRef = ref<InstanceType<typeof Account>>()
</script>

<style lang="scss" scoped>
.panel {
  width: 330px;
}
.title {
  font-size: 28px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
}
.controns {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0;
}
:deep(.el-button) {
  width: 330px;
  height: 36px;
}
.custom-tabs-label {
  display: flex;
  align-items: center;
  justify-content: center;
  .text {
    padding-left: 5px;
  }
}
</style>
